package com.micro;

import weibo4android.Weibo;
import weibo4android.WeiboException;
import weibo4android.http.RequestToken;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;

public class AddAcountActivity extends Activity implements OnClickListener {
	Weibo weibo = new Weibo();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		weibo.setToken(Weibo.CONSUMER_KEY, Weibo.CONSUMER_SECRET);
		setContentView(R.layout.add_account);
		findViewById(R.id.add_new_sina_account).setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.add_new_sina_account: {
			addSinaView();
			break;
		}
		}
	}

	private void addSinaView() {
		System.setProperty("weibo4j.oauth.consumerKey", Weibo.CONSUMER_KEY);
		System.setProperty("weibo4j.oauth.consumerSecret",
				Weibo.CONSUMER_SECRET);
//		Weibo weibo = new Weibo();
		RequestToken requestToken;
		try {
			requestToken = weibo
					.getOAuthRequestToken("smartposter://RegisterSinaAccountActivity");
			com.sina.oauth.OAuthConstant.getInstance().setRequestToken(
					requestToken);
			
			Uri uri = Uri.parse(requestToken.getAuthenticationURL()
					+ "&display=mobile");
			startActivity(new Intent(Intent.ACTION_VIEW, uri));
		} catch (WeiboException e) {
			e.printStackTrace();
		}
	};

}
